<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['set']=$this->plugin_setting('basic');
$keywords=$this->plugin_setting('search');
$return['params']=array('jy'=>1);
if($_RQ['op']=='main'){
	//下面list,PC端需要获取商品列表
	$params=array(
		'uniacid'=>$_SESSION['uniacid'],
		'status'=>1,
		'nochecked'=>0,
		'no_showsys'=>0,
		'type <>'=>4
	);
	$searchkeyword=$this->plugin_setting('search')['keyword'];
	$return['searchkeyword']=explode(';',$searchkeyword);
	if($_RQ['cid']){
		$params['ccate']=intval($_RQ['cid']);
		$return['params']['ccate']=intval($_RQ['cid']);
	}
	
	if(trim($_RQ['keyword'])){
		$params['title like']='%'.trim($_RQ['keyword']).'%';
		$return['params']['keyword']=trim($_RQ['keyword']);
	}
	if($_RQ['pid']){
		$params['pcate']=intval($_RQ['pid']);
		$return['params']['pid']=intval($_RQ['pid']);
	}else{
		$return['params']['pid']=0;
	}
	if($_RQ['order']=='isrecommand'){
		$params['saletype likes']=array('1');
		$return['params']['order']='isrecommand';
	}
	if($_RQ['order']=='isnew'){
		$params['saletype likes']=array('2');
		$return['params']['order']='isnew';
	}
	if($_RQ['order']=='ishot'){
		$params['saletype likes']=array('3');
		$return['params']['order']='ishot';
	}
	if($_RQ['priceMin']){
		$params['price >=']=intval($_RQ['priceMin']);
		$return['params']['priceMin']=intval($_RQ['priceMin']);
	}
	if($_RQ['priceMax']){
		$params['price <=']=intval($_RQ['priceMax']);
		$return['params']['priceMax']=intval($_RQ['priceMax']);
	}
	$params['onepluginname']='';
	//进一步整理筛选条件，商品属性字段是否需 要调整，商品分类如何筛选，orderby如何整理
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	if($_RQ['num']){
		$psize=$_RQ['num'];
	}
	$total='';
	$fields=array('id','title','image','price','active_plugin','active_id','salenum','originalprice','usermaxbuy','unit');
	$orderby='paixu desc, star desc, id desc ';
	if($_RQ['order']){
		if($_RQ['order']=='sales'){
			$orderby='salerealnum desc';
		}
		if($_RQ['order']=='price'){
			if($_RQ['order_type']==2){
				$orderby='price desc';
			}else{
				$orderby='price asc';
			}
			
		}
	}
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'fields'=>$fields,
		'orderby'=>$orderby,
	);
	//PC端先关闭获取，教给JS
	if($_SESSION['os']=='windows' && false){
		if($_RQ['order']=='sale_offer'){
			$list=model('jy_weishop/activity/sales')->getoffer();
		}else{
			$list=model('jy_weishop/goods')->goods_list($parameter,$total);
		}
	}
	$return['list']=array();
	$return['order']=$_RQ['order'];
	//最近浏览
	$params=array(
		//'table'=>'jy_weishop_member_history',
		'params'=>array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),
		'fields'=>array('id','goodsid','merchid','createtime'),
		'orderby'=>'createtime desc',
		'limit'=>'5',
	);
	if($_SESSION['os']=='windows'){
		$hlist=pdo_getlist('jy_weishop_member_history',$params);
	}
	if($hlist){
		foreach($hlist as &$row){
			$goods=model('jy_weishop/goods')->goods_detail($row['goodsid'],array('title','image','price'));
			$row=array_merge($goods,$row);
		}
	}
	$return['hlist']=$hlist;
	$groupparams=array('uniacid'=>$_SESSION['uniacid'],'mid'=>0,'isshow'=>1,'parentid'=>0);
	$onepluginname=model('jy_weishop/goods')->is_onegoods('jy_liveshop');
	if($onepluginname){
		$groupparams['onepluginname']=$onepluginname;
	}else{
		$groupparams['onepluginname']='';
	}
	$category=pdo_getall('jy_weishop_goods_group',$groupparams,array(),'id','paixu desc');
	foreach($category as &$item){
		$item['childs']=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>1,'parentid'=>$item['id']),array(),'id','paixu desc');
	}
	//推荐分类
	$groupparams['isrecommand']=1;
	$recommend=pdo_getall('jy_weishop_goods_group',$groupparams);
	$return['recommend']=$return['childs']=$recommend;
	$return['category']=$category;
	$title=$return['setting']['share_title']?'全部商品'.$return['setting']['share_title']:'全部商品-在线商城';
	$desc=$return['setting']['share_desc']?'商品列表-'.$return['setting']['share_desc']:'在线商城，一个属于自己的个人商城！';
	if($_RQ['pcate'] || $_RQ['pid']){
		$pcate=$_RQ['pcate']?intval($_RQ['pcate']):intval($_RQ['pid']);
		$return['params']['pcate']=$pcate;
		$pcateinfo=pdo_get('jy_weishop_goods_group',array('id'=>$pcate));
		$title=$pcateinfo['title'];
		$desc=$pcateinfo['desc'];
	}
	if($_RQ['ccate'] || $_RQ['cid']){
		$ccate=$_RQ['ccate']?intval($_RQ['ccate']):intval($_RQ['cid']);
		$return['params']['ccate']=$ccate;
		$pcateinfo=pdo_get('jy_weishop_goods_group',array('id'=>$pcate));
		$title=$pcateinfo['title'];
		$desc=$pcateinfo['desc'];
	}elseif($_RQ['order']=='isrecommand'){
		$title='推荐商品';
	}elseif($_RQ['order']=='isnew'){
		$title='新品上市';
	}elseif($_RQ['order']=='ishot'){
		$title='热卖商品';
	}elseif($_RQ['order']=='issendfree'){
		$title='包邮商品';
	}
	$return['sysparams']=pdo_getall('jy_weishop_goods_param',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'is_so'=>1));
	foreach($return['sysparams'] as &$pv){
		$pv['content']=json_decode($pv['content'],true);
	}
	$return['catlevel']=2;
	$return['opencategory']=true;
	$return['feemoney']=$this->plugin_setting('feemoney');
	$return['sharedata']=array(
		'title'=>$title.'-'.$return['shopset']['title'],
		'desc'=>$desc,
		'link'=>custom_url('jy_liveshop/goods.index//fromuser='.$_SESSION['uid'].'&onemerchid='.$_SESSION['onemerchid'],true),
		'imgUrl'=>ATTACHMENT_URL.$return['setting']['share_image']
	);
	$keywords='商品列表,'.$return['setting']['share_keywords']?:$return['sharedata']['desc'];
	$keywords=$pcateinfo['keywords']?:$keywords;
	set_html('title','商品列表');
	set_html('description',$desc);
	set_html('keywords',$keywords);
	exi($return);
}
// js 获取数据
if($_RQ['op']=='getlist'){
	$params=array(
		'uniacid'=>$_SESSION['uniacid'],
		'status'=>1,
		'nochecked'=>0,
		'no_showsys'=>0,
		'type <>'=>4,
	);
	$onepluginname=model('jy_weishop/goods')->is_onegoods('jy_liveshop');
	if($onepluginname){
		$params['onepluginname']=$onepluginname;
	}else{
		$params['onepluginname']='';
	}
	if($_SESSION['onemerchid']){
		$params['merchid']=$_SESSION['onemerchid'];
		unset($params['no_showsys']);
		unset($params['onepluginname']);
	}
	//print_r($params);exit;
	$list=model('jy_weishop/goods_item')->goodslist($params);
	if(empty($list)){
		exi('none');
	}else{
		exi($list);
	}
}	
?>